<html>
<head><meta charset="utf-8"><title>const bitflags · t-compiler/const-eval · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/index.html">t-compiler/const-eval</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html">const bitflags</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205067602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20bitflags/near/205067602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html#205067602">(Jul 26 2020 at 21:12)</a>:</h4>
<p>What would be the blockers for using <a href="https://crates.io/crates/bitflags">bitflags</a> as the value of a <code>const</code>:</p>
<div class="codehilite"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">MY_FLAGS</span>: <span class="nc">SomeFlags</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">SomeFlags</span>::<span class="n">A</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">SomeFlags</span>::<span class="n">B</span><span class="p">;</span><span class="w"></span>
</code></pre></div>



<a name="205067845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20bitflags/near/205067845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html#205067845">(Jul 26 2020 at 21:18)</a>:</h4>
<p>Unless we special case it somehow, const traits or their equivalent, I think.</p>
<p>But you should be able to do something like <code>const MY_FLAGS: SomeFlags = SomeFlags::new(SomeFlags::A.bits | SomeFlags::B.bits);</code> today perhaps?</p>



<a name="205067854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20bitflags/near/205067854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html#205067854">(Jul 26 2020 at 21:19)</a>:</h4>
<p>I guess it'd be <code>SomeFlags::from_bits_truncate(SomeFlags::A.bits() | SomeFlags::B.bits());</code></p>



<a name="205072332"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20bitflags/near/205072332" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html#205072332">(Jul 26 2020 at 23:49)</a>:</h4>
<p>Ah, interesting. I don't think I care strongly enough about working around it to make a constant that I'd want to dig into <code>.bits</code> like that, but nonetheless that's good to know.</p>



<a name="205072765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20bitflags/near/205072765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html#205072765">(Jul 27 2020 at 00:02)</a>:</h4>
<p>Though, hmmm, I could wrap that in a macro.</p>



<a name="205072766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/146212-t-compiler/const-eval/topic/const%20bitflags/near/205072766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/146212-t-compiler/const-eval/topic/const.20bitflags.html#205072766">(Jul 27 2020 at 00:02)</a>:</h4>
<p><span class="user-mention" data-user-id="116122">@simulacrum</span> Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>